package info.techgeek.labs.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by IntelliJ IDEA.
 * User: techgeek
 * Date: 27-lug-2006
 * Time: 9.00.32
 * To change this template use File | Settings | File Templates.
 */
public class DAOConnectionManager {
	
    private static DAOConnectionManager dbuiConnectionManager = new DAOConnectionManager();
    private DAOConnectionManager(){

    }
    public static DAOConnectionManager getInstance()
    {
        return dbuiConnectionManager;
    }
    public Connection getConnection(String proxyUser)
    {
        System.out.println("ProxyUser connection called : "+proxyUser);
        Connection conn = null;
        try {
             //Load and register Oracle driver
        	
                	Class.forName("oracle.jdbc.driver.OracleDriver");
//                    DriverManager.registerDriver(new OracleDriver());
  
                	/*
                    javax.naming.InitialContext initCtx = new javax.naming.InitialContext();
                    Context envCtx = (Context) initCtx.lookup("java:comp/env");
                    System.out.println("Before DataSource ");
                    DataSource ds = (DataSource) envCtx.lookup("jdbc/dbui");
                    System.out.println("Before BasicDataSource " );
                    
                    System.out.println("After BasicDataSource " );
                    
                    if (ds != null) {
                    	System.out.println("ds");
                    	    BasicDataSource bds = (BasicDataSource)ds;

                    		System.out.println("ds2");
                    		String username = bds.getUsername();
                    		String password = bds.getPassword();
                    		String dbUrl = bds.getUrl();      
                    		
                    		System.out.println("conUser "+username);
                    		System.out.println("conPassword "+password);
                    		System.out.println("conUrl "+dbUrl);
                	}
                    else 
                    { 
                    	System.out.println("No DataSource"); 
                	}
                }
                    
                	 */
                    
//              javax.sql.DataSource ds = (javax.sql.DataSource) envCtx.lookup("jdbc/dbui");
//              oracleConnection.get
//              DataSource ds = (BasicDataSource)envCtx.lookup("jdbc/dbui");
                    
//	          String conUser = ds.getUser();
//	          String conPassword = ds.getPassword();
//	          String conUrl = ds.getUrl();
	            
////	          System.out.println("conUser "+conUser);
//	          System.out.println("conPassword "+conPassword);
//	          System.out.println("conUrl "+conUrl);
                    
              conn = DriverManager.getConnection("jdbc:oracle:thin:@2322.540.541.211:2483:techgeek","dbu","dbu");
//              conn = DriverManager.getConnection("jdbc:oracle:thin:@"+"ORABE_DBUI","dbui","dbui");
                	
                    //OracleOCIConnectionPool ods;
                
        }catch (Exception e)
        {
            e.printStackTrace();
        } 
        return conn;
    }
    
    public void closeConnections(ResultSet  resultSet, Statement  statement,Connection connection ) {
		if ( resultSet != null ){
			try {
				resultSet.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if ( statement != null ){
			try {
				statement.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if ( connection != null ){
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

 }
 